﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using WebManagerSystem1.Models;

namespace WebManagerSystem1.Controllers
{
    public class DefaultController : Controller
    {
        private readonly ILogger<DefaultController> _logger;

        public DefaultController(ILogger<DefaultController> logger)
        {
            _logger = logger;
        }

        public IActionResult Index()
        {
            return View();
        }
        public IActionResult Login()
        {
            return View();
        }
        public IActionResult GetVerifyCode()
        {
            BaseLibrary.ClassLibrary.VerifyCode verifyCode = new BaseLibrary.ClassLibrary.VerifyCode();
            UserSession.VerifyCode = verifyCode.CreateVerifyCode(6);
            string code = UserSession.VerifyCode;
            var img = verifyCode.CreateImageCode(code);
            return File(BaseLibrary.ClassLibrary.CDrawing.CImg.ImgToByte(img), @"image/jpeg");
        }
        public IActionResult Logout()
        {
            Models.UserSession.Logout();
            return new JsonResult("成功");
        }
        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
